// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var leftMenu = require("../leftMenu/leftMenu");
	var topMenu = require("../topMenu/topMenu");
	var router = require("../hash/pageRouter");
	var dialog = require("dialog");
	var validate = require("validate");
	var databind = require("databind");
	var constant = require("constant");
	var css_financingDetailInfo = require("../financing/financingDetailInfo.css");
	var css_receivablesNotice = require("./receivablesNotice.css");

	var js_platform_main = require("./platform_main.js");
	var pageIndex = 1,
		pageSize = 10,
		totalPageCount = 1,
		totalRecordCount = 0; //分页初始化
	var imgSrc;
	var left;
	var pickupId;
	var auditAmount;
	var receivedAmount;
	var enterpriseId;
	var init = function(page) {
		
		pickupId = page.params.pickupId || base.getUrlParam("pickupId");
		left = page.params.left || base.getUrlParam("left");
		$(".left").removeClass("none");
		leftMenu.init(6);
		$(".table-section").removeClass("none");
		$(".footer").removeClass("none");
		$("#main").css("background", "#ffffff");
		$("#leftMenu7").find(".leftMenu-item").removeClass("leftMenu-active");
		$("#leftMenu7 .leftMenu li:first-child").addClass("leftMenu-open");
		$("#leftMenu7").find(".leftMenu-item").eq(left).addClass("leftMenu-active");
		js_platform_main.init(0);
		inquirePickupApplicationDetail();
		initEvent();
		router.init();
		
			var css_deliveryNotice = require("./deliveryNotice.css");
	};
	var initEvent = function() {
		//若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == "" || base.getData("sid") == undefined) {
			top.location.href = "../login/login.html";
		}
		
		//点击首页
		$(".platform_main").unbind("click").click(function(){
			top.location.href = "../main/platform_main.html";
		});
		
	//点击收款列表
	$(".receivablesNoticeList").unbind("click").click(function(){
		router.route("main/receivablesNotice_list.html?left=7", true);
		});
		
		//点击收款
		$(".platformBtns").on("click",".button-receivables",function(){
			router.route("main/receivablesNotice_receivables.html?pickupId="+pickupId+"&auditAmount="+auditAmount+"&receivedAmount="+receivedAmount+"&enterpriseId="+enterpriseId+"&left="+left, true);
		
		});
	};


	//绑定物流公司
	var loadLogisticsCompanyPageList = function(bodyDomId, jsTpl) {
		base.fnAjax({
			action: "inquireLogisticsCompanyListByCompanyName.json",
			version: "v1.0",
			async: false,
			oData: {
				pageIndex: 1,
				pageSize: 50
			}, //传递参数
			fnSuccess: function(data) { //成功回调
				if (data.status == 200) {
					juicer.register("getValueByKey", constant.getValueByKey);
					var tpl = $("#" + jsTpl).html();
					var html = juicer(tpl, data);
					$("#" + bodyDomId).html(html);

				} else {
					base.alert(3, data.message);
				}
			}
		});

		//下发运输通知   绑定点击物流方事件
		$("#transportCompanyName").change(function() {

			var companyName = $("#transportCompanyName option:selected").text();
			$(".supervisionCompanyNameInput").val(companyName);
		});

		//绑定点击物流方事件
		$("#supervisionCompanyName").change(function() {

			var companyName = $("#supervisionCompanyName option:selected").text();
			$(".supervisionCompanyNameInput").val(companyName);
		});
	}


	var inquirePickupApplicationDetail = function(){
		base.fnAjax({
			action: "inquireNormalPickupApplicationDetail.json",
			oData: {
				pickupId: pickupId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					juicer.register("getValueByKey", constant.getValueByKey);
					auditAmount = data.datas[0].auditAmount;
					receivedAmount = data.datas[0].receivedAmount;
					enterpriseId = data.datas[0].enterpriseId;
					var html;
					var pickupDetailTpl = $("#pickupDetailTpl").html();
					if (pickupDetailTpl != undefined) {
						html = juicer(pickupDetailTpl, data);
					}
					$(".tab1").html(html);
					$(".receivableNoticeDetail").unbind("click").click(function(){
						router.route("bulkstockTallyDetail/bulkstockTallyDetail.html?inventoryId="+$(this).parents("tr").attr("inventoryId"));
					});
						
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	}

	return {
		init: init
	};
});